package com.todo.strategy.online.infrastructure.convert;

import com.alibaba.fastjson.JSONObject;
import com.google.api.client.util.Lists;
import com.todo.strategy.online.infrastructure.entity.domain.MemoTemplateDO;
import com.todo.strategy.online.infrastructure.entity.domain.MemoUserRelationDO;
import com.todo.strategy.online.infrastructure.entity.model.MemoTemplateContentModel;
import com.todo.strategy.online.infrastructure.entity.model.MemoUserRelationContentModel;
import com.todo.strategy.online.infrastructure.entity.po.MemoTemplatePO;
import com.todo.strategy.online.infrastructure.entity.po.MemoUserRelationPO;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;

/**
 * @author azhebuxing
 * @date 2024/11/28 02:22
 * @description
 */
public class MemoConvert {

    public static MemoTemplatePO convertToMemoTemplatePO(MemoTemplateDO memoTemplateDO) {
        if (memoTemplateDO == null) {
            return null;
        }
        MemoTemplatePO memoTemplatePO = new MemoTemplatePO();
        memoTemplatePO.setId(memoTemplateDO.getId());
        memoTemplatePO.setName(memoTemplateDO.getName());
        memoTemplatePO.setDesc(memoTemplateDO.getDesc());
        memoTemplatePO.setContent(JSONObject.toJSONString(memoTemplateDO.getContentModel()));
        memoTemplatePO.setBaseType(memoTemplateDO.getBaseType());
        memoTemplatePO.setReferenceOpinion(memoTemplateDO.getReferenceOpinion());
        memoTemplatePO.setSuggestStrategy(memoTemplateDO.getSuggestStrategy());
        memoTemplatePO.setUserId(memoTemplateDO.getUserId());
        memoTemplatePO.setCreateTime(memoTemplateDO.getCreateTime());
        memoTemplatePO.setUpdateTime(memoTemplateDO.getUpdateTime());
        memoTemplatePO.setIsPlatform(memoTemplateDO.getIsPlatform());
        memoTemplatePO.setUseCount(memoTemplateDO.getUseCount());
        memoTemplatePO.setStatus(memoTemplateDO.getStatus());
        memoTemplatePO.setIsDelete(memoTemplateDO.getIsDelete());
        return memoTemplatePO;
    }

    public static MemoTemplateDO convertToMemoTemplateContentDO(MemoTemplatePO memoTemplatePO) {
        if (memoTemplatePO == null) {
            return null;
        }
        MemoTemplateDO memoTemplateDO = new MemoTemplateDO();
        memoTemplateDO.setId(memoTemplatePO.getId());
        memoTemplateDO.setName(memoTemplatePO.getName());
        memoTemplateDO.setDesc(memoTemplatePO.getDesc());
        memoTemplateDO.setContentModel(JSONObject.parseObject(memoTemplatePO.getContent(), MemoTemplateContentModel.class));
        memoTemplateDO.setBaseType(memoTemplatePO.getBaseType());
        memoTemplateDO.setReferenceOpinion(memoTemplatePO.getReferenceOpinion());
        memoTemplateDO.setSuggestStrategy(memoTemplatePO.getSuggestStrategy());
        memoTemplateDO.setUserId(memoTemplatePO.getUserId());
        memoTemplateDO.setCreateTime(memoTemplatePO.getCreateTime());
        memoTemplateDO.setUpdateTime(memoTemplatePO.getUpdateTime());
        memoTemplateDO.setIsPlatform(memoTemplatePO.getIsPlatform());
        memoTemplateDO.setUseCount(memoTemplatePO.getUseCount());
        memoTemplateDO.setStatus(memoTemplatePO.getStatus());
        memoTemplateDO.setIsDelete(memoTemplatePO.getIsDelete());
        return memoTemplateDO;
    }

    public static List<MemoTemplateDO> convertToMemoTemplatePOList(List<MemoTemplatePO> memoTemplatePOList) {
        if (CollectionUtils.isEmpty(memoTemplatePOList)) {
            return Lists.newArrayList();
        }
        return memoTemplatePOList.stream().map(MemoConvert::convertToMemoTemplateContentDO).collect(java.util.stream.Collectors.toList());
    }

    public static MemoUserRelationPO convertToMemoUserRelationPO(MemoUserRelationDO memoUserRelationDO) {
        if (memoUserRelationDO == null) {
            return null;
        }
        MemoUserRelationPO memoUserRelationPO = new MemoUserRelationPO();
        memoUserRelationPO.setId(memoUserRelationDO.getId());
        memoUserRelationPO.setPlanId(memoUserRelationDO.getPlanId());
        memoUserRelationPO.setUserId(memoUserRelationDO.getUserId());
        memoUserRelationPO.setContent(JSONObject.toJSONString(memoUserRelationDO.getContent()));
        memoUserRelationPO.setIsFinish(memoUserRelationDO.getIsFinish());
        memoUserRelationDO.setRemark(memoUserRelationDO.getRemark());
        memoUserRelationPO.setIsDelete(memoUserRelationDO.getIsDelete());
        memoUserRelationPO.setCreateTime(memoUserRelationDO.getCreateTime());
        memoUserRelationPO.setUpdateTime(memoUserRelationDO.getUpdateTime());
        return memoUserRelationPO;
    }

    public static MemoUserRelationDO convertTomemoUserRelationDO(MemoUserRelationPO memoUserRelationPO) {
        if (memoUserRelationPO == null) {
            return null;
        }
        MemoUserRelationDO memoUserRelationDO = new MemoUserRelationDO();
        memoUserRelationDO.setId(memoUserRelationPO.getId());
        memoUserRelationDO.setPlanId(memoUserRelationPO.getPlanId());
        memoUserRelationDO.setUserId(memoUserRelationPO.getUserId());
        memoUserRelationDO.setContent(JSONObject.parseObject(memoUserRelationPO.getContent(), MemoUserRelationContentModel.class));
        memoUserRelationDO.setIsFinish(memoUserRelationPO.getIsFinish());
        memoUserRelationDO.setRemark(memoUserRelationPO.getRemark());
        memoUserRelationDO.setIsDelete(memoUserRelationPO.getIsDelete());
        memoUserRelationDO.setCreateTime(memoUserRelationPO.getCreateTime());
        memoUserRelationDO.setUpdateTime(memoUserRelationPO.getUpdateTime());
        return memoUserRelationDO;
    }
}
